package com.my.test.thread.atomic;

import java.util.concurrent.atomic.AtomicReference;

public class TestAtomicReference {


    public static void main(String[] args) {
        AtomicReference<User> ar = new AtomicReference();
        User u = new User("hello", 10);
        ar.set(u);
        User updateU = new User("world", 17);
        ar.compareAndSet(u, updateU);
        System.out.println(ar.get().getAge());
        System.out.println(ar.get().getName());
    }

    static class User {

        private String name;

        private int age;

        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
